﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR;
using FunctionalCLR.Core;

namespace FunctionalCLR.Shell.Function.IO {

    /// <summary>
    /// filename = "c:\text.txt";
    /// write(filename, "hello, world!");
    /// </summary>
    public class WriteNode : FuncNode {

        public WriteNode()
            : base() {
            base.Value = "write";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            string path = ((StringNode)Children[0]).Value;
            string content = ((StringNode)Children[1]).Value;

            System.IO.File.WriteAllText(path, content);

            return string.Empty;
        }
    }
}
